//
// Created by YueChuan on 2023/5/2.
//
#include "tcp_server.h"
#include "iomanager.h"
#include "log.h"

yuechuan::Logger::ptr g_logger = YUECHUAN_LOG_ROOT();


void run() {
    auto addr = yuechuan::Address::LookupAny("0.0.0.0:8033");
//    auto addr2 = yuechuan::UnixAddress::ptr(new yuechuan::UnixAddress("/tmp/unix_sock"));
    std::vector<yuechuan::Address::ptr> addrs;
    addrs.push_back(addr);
//    addrs.push_back(addr2);
    yuechuan::TcpServer::ptr tcp_server(new yuechuan::TcpServer);
    std::vector<yuechuan::Address::ptr> fails;
    while (!tcp_server->bind(addrs, fails)) {
        sleep(2);
    }
    tcp_server->start();
    YUECHUAN_LOG_INFO(g_logger) << addr->toString();
}

int main(int argc, char **argv) {
    yuechuan::IOManager iom(2);
    iom.schedule(run);
    return 0;
}
